<?php
namespace Action;
class Check extends Daniuwo{
    // 检测
	public function index()
	{
		$url = htmlentities(X('get.url'));
        $path = htmlentities(X('get.path'));
        // 参数检测
		if(empty($url)){
			return $this->json(array(
                'error'=>'0',
                'code'=>'0',
                'msg'=>"参数错误",
            ));
        }
        // 检测盗版网站
        $data = S('shouquan')->find('*',['domain'=>$url]);
        // 网站没授权
		if(empty($data)){
            // 是否记录过
            if(!S('daoban')->count(['domain'=>$url])){
                // 记录盗版网站
                S('daoban')->insert([
                    'domain'=>$url,
                    'path'	=>$path,
                    'atime' =>NOW_TIME
                ]);
            }
            // 如果已经存在记录就更新记录时间
            S('daoban')->update([
                    'path'	=>$path,
                    'atime' =>NOW_TIME
                ],[
                    'domain'=>$url
                ]);
            // 返回未授权提示
            return $this->json(array(
                'error'=>'0',
                'code'=>'0',
                'msg'=>$this->conf['no_msg'].$this->conf['tongji'],
            ));
        }
        // 网站已授权但被锁定
        if($data['state'] == 0){
            return $this->json(array(
                'error'=>'0',
                'code'=>'0',
                'msg'=>$this->conf['key_msg'].$this->conf['tongji'],
            )); 
        }
        // 网站已授权
        return $this->json(array(
            'error'=>'1',
            'code'=>'1',
            'msg'=>"".$this->conf['tongji'],
        ));

	}
}